using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FilesWebService;

public partial class List : System.Web.UI.Page
{
    private FilesWS _filesWS;
    private StoredFileInfo[] _files;

    private void initializeServices()
    {
        AuthHeader authentication;

        _filesWS = new FilesWS();
        authentication = new AuthHeader();
        authentication.Username = this.Session["username"] as String;
        authentication.Password = this.Session["password"] as String;

        _filesWS.AuthHeaderValue = authentication;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        initializeServices();

        this._files = _filesWS.GetUserFiles();

        Response.Clear();

        Response.ContentType = "text/xml";
        Response.Expires = 0;
        Response.CacheControl = "private";

        Response.Write("<?xml version='1.0'?><fileList user='" + (String)this.Session["username"] + "'>");        

        foreach (StoredFileInfo sfi in _files)
        {
            Response.Write("<file name='");
            Response.Write(sfi.Name);

            Response.Write("' folder='");
            Response.Write(sfi.Folder);

            Response.Write("' ip='");
            Response.Write(sfi.Ip);

            Response.Write("' />");
        }

        Response.Write("</fileList>");        
    }
}
